package demo.kk;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class StressTest {
    public static void main(String[] args) throws InterruptedException {


    }
    
    private static boolean runSingleTest() throws InterruptedException {
        final Set<Singleton3> instances = Collections.synchronizedSet(new HashSet<>());
        final CountDownLatch latch = new CountDownLatch(50);
        
        ExecutorService executor = Executors.newFixedThreadPool(50);
        
        for (int i = 0; i < 1000; i++) {
            executor.submit(() -> {
                instances.add(Singleton3.getSingleton3());
                latch.countDown();
            });
        }
        
        latch.await();
        executor.shutdown();
        
        boolean passed = instances.size() == 1;
        if (!passed) {
            System.out.println("发现 " + instances.size() + " 个实例！");
        }
        return passed;
    }
}